﻿declare var mvcModel: any;
module WorkBasket.Instance {

    WorkbasketApp.controller('wbInstanceCTRL',
        function ($scope) {
            $scope.WorkflowID = mvcModel.WorkflowID;
            $scope.InstanceData = mvcModel.InstanceData;
            $scope.InstanceID = mvcModel.InstanceID;
            $scope.InstanceHistoryID = mvcModel.InstanceHistoryID;
            $scope.StepID = mvcModel.StepID;
            $scope.ProcessVersionID = mvcModel.ProcessVersionID;
            $scope.Status = null;

            var SOC = WorkBasket.SOC;
            $scope.Submit = function () {
 
                SaveData("complete");

            }

            $scope.Save = function () {
 
                SaveData("draft");

            }
            //helpers
 
            function SaveData(status: string) {
                var instancehistory = new WorkBasket.Entities.InstanceHistory($scope.InstanceHistoryID,
                    $scope.InstanceID,
                    JSON.stringify($scope.InstanceData),
                    0,
                    null, $scope.StepID, status);
                var objhist: any = SOC.InstanceHistorys().SaveData(instancehistory);
                $scope.InstanceID = objhist.InstanceID;
                $scope.InstanceHistoryID = objhist.InstanceHistoryID;
                $scope.Status = objhist.Status;
            }



        })

}